import {NzButtonType} from "ng-zorro-antd/button";
import {ModalTypes} from "ng-zorro-antd/modal";

type EmitterEvent = () => void

export class ModalData {
  get visible(): boolean {
    return this._visible;
  }

  set visible(value: boolean) {
    this._visible = value;
  }

  set onClose(value: EmitterEvent) {
    this._onClose = value;
  }

  set onCancel(value: EmitterEvent) {
    this._onCancel = value;
  }

  set onOk(value: EmitterEvent) {
    this._onOk = value;
  }

  private _onOk: EmitterEvent = () => {
    this._visible = false;
  }
  private _onCancel: EmitterEvent = () => {
    this._visible = false;
  }
  private _onClose: EmitterEvent = () => {
    this._visible = false;
  }

  get onOk(): EmitterEvent {
    return this._onOk
  }

  get onCancel(): EmitterEvent {
    return this._onCancel
  }

  get onClose(): EmitterEvent {
    return this._onClose
  }

  message: string = ""
  okType: NzButtonType = "primary"
  private _visible: boolean = false
  title: string = "提示"
  modalType: ModalTypes = "default"

  constructor(params: ModalInter) {
    this.message = params.message;
    if (params.title !== undefined) {
      this.title = params.title;
    }
    if (params.visible !== undefined)
      this.visible = params.visible;
    else
      this.visible = true;
    if (params.okType !== undefined)
      this.okType = params.okType;
    if (params.onOk !== undefined)
      this.onOk = params.onOk;
    if (params.onCancel !== undefined)
      this.onCancel = params.onCancel;
    if (params.onClose !== undefined)
      this.onClose = params.onClose;
  }
}

interface ModalInter {
  message: string,
  title?: string,
  visible?: boolean,
  modalType?: ModalTypes,
  okType?: NzButtonType,
  onOk?: EmitterEvent,
  onCancel?: EmitterEvent,
  onClose?: EmitterEvent
}

//使用RzMessage弹出消息提示
export function RzMessage(
  param: ModalData) {
  modal.RzModalEvent(param);
}

class Modal {
  public RzModalEvent: (param: ModalData) => void = (param: ModalData) => {
  };
}

const modal = new Modal();
export default modal;
